package com.hxd.dao;

import com.hxd.pojo.Page;
import com.hxd.pojo.Users;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class UserDaoUtil {
    public String selectOneuser(@Param("users") final Users users,@Param("page") final Page<Users> page){
        return new SQL(){
            {
                this.SELECT("ID,nickname,username,logoncount,mobile,birthday,phone,workphone");
                this.FROM("users");
                this.WHERE("1=1");
                if(!"".equals(users.getNickname())&&users.getNickname()!=null){
                    this.WHERE("nickname=#{users.nickname}");
                }
                if(users.getMobile()!=0){
                    this.WHERE("mobile=#{users.mobile}");
                }
                if(users.getLogoncount()!=0){
                    this.WHERE("logoncount=#{users.logoncount}");
                }
                this.LIMIT("#{page.pageStartIndex},#{page.pageSiae}");
            }}.toString();
    }
    public String selectOneusernum(@Param("users") final Users users,@Param("page") final Page<Users> page){
        return new SQL(){
            {
                this.SELECT("count(*)");
                this.FROM("users");
                this.WHERE("1=1");
                if(!"".equals(users.getNickname())&&users.getNickname()!=null){
                    this.WHERE("nickname=#{users.nickname}");
                }
                if(users.getMobile()!=0){
                    this.WHERE("mobile=#{users.mobile}");
                }
                if(users.getLogoncount()!=0){
                    this.WHERE("logoncount=#{users.logoncount}");
                }
            }}.toString();
    }
}
